package com.sptpc.demo1.controller;


import com.sptpc.demo1.model.Category;
import com.sptpc.demo1.model.Drink;
import com.sptpc.demo1.service.ICategoryService;
import com.sptpc.demo1.service.IDrinkService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;


    @GetMapping("/")
    public String Index() {
        return "manage/login";
    }

    @GetMapping("/manage/index")
    public String adminIndex() {
        return "manage/index";
    }

    @GetMapping("/manage/welcome")
    public String welcome() {
        return "manage/welcome";
    }

    @GetMapping("/menu/drink")
    public String drinkIndex() {
        return "drink/index";
    }

    @GetMapping("/drink/addform")
    public String drinkaddFrom(){
        return "drink/add";
    }
    //饮品修改页路由
    // get /drink/updateform?id=13
    @GetMapping("/drink/updateform")
    public ModelAndView drinkupdateFrom(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("drink/edit");
        Category category=categoryService.getCategoryById(id);
        // TODO: 从数据库通过id查询出对应饮品信息
//        Drink build = Drink.builder().id(13)
//                .name("茉莉花茶")
//                .price(Money.of(CurrencyUnit.of("CNY"),12.00))
//                .build();

//        Drink drink = drinkService.getDrinkById(id);
        mv.addObject("data",category);
        return mv;
    }

    @GetMapping("/id")
    public String DeleteDrink() {
        return "drink/add";
    }
    @GetMapping("/menu/category")
    public String category() {
        return "category/index";
    }
}
